package com.yunao.commons.serachcore.utils;

import org.apache.commons.lang3.ArrayUtils;

import javax.servlet.http.HttpServletRequest;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;

public class RequestParamUtils {
	
	public static Map<String, String> parseParams(HttpServletRequest request) {
		final String[] keys = { "id", "sort", "title", "author", "domain", 
				"host", "source", "media_type", "channel", "emotion",
				"author_type", "domain_level", "location", "domestic", 
				"nr", "ns", "nt", "mode", "keywords", "limit", "between",
				"greaterequal", "greaterthan","days", "offset", "message_type",
				"stop_words", "trim_article", "max_word", "max_group", "distance", 
		};
		Map<String, String> m = new HashMap<>();
		Enumeration<String> e = request.getParameterNames();
		while (e.hasMoreElements()) {
			String key = e.nextElement();
			if (ArrayUtils.contains(keys, key)) {
				m.put(key, request.getParameter(key));
			}
		}
		return m;
	}

}
